<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/3/26
  Time: 19:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path=request.getContextPath()+"/"; %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <base href="<%=path%>">
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="layui/css/font.css">
    <link rel="stylesheet" href="layui/css/xadmin.css">
    <script type="text/javascript" src="layui/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="layui/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="childrenBody">
<form class="layui-form" id="form" style="width:80%;"  >
    <input type="hidden" name="id" value="${dept.id}" />
    <div class="layui-form-item">
        <label class="layui-form-label">部门编号</label>
        <div class="layui-input-block">
            <input type="text" name="deptCode" value="${dept.deptCode}" class="layui-input userName" lay-verify="required" placeholder="请输入部门编号">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-block">
            <input type="text" name="deptName" value="${dept.deptName}" class="layui-input userName" lay-verify="required" placeholder="请输入部门名称">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" lay-filter="ofilter" lay-skin="switch" lay-text="开启|关闭"<c:if test="${dept.flag==1}">checked</c:if>>
            </div>
            <input type="hidden" id="flag" value="${dept.flag}" name="flag" />
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" id="msubmit" >立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="layui/layui/layui.js"></script>
<%--<script type="text/javascript" src="addUser.js"></script>--%>
<script type="text/javascript" >
    layui.use(['form','layer','jquery'],function () {
        let form=layui.form;
        layer=layui.layer;
        var $=layui.jquery;
        form.render();
        //点击提交，提交表单
        $("#msubmit").click(function () {
            var param = $("#form").serialize();
            $.ajax({
                url:"system/dept/save",
                type:"post",
                dataType:"json",
                data:param,
                success:function (ret) {
                    if (ret.status){
                        layer.msg("操作成功",function () {
                            //刷新父页面
                            parent.document.location='system/dept/data';
                            //关闭当前弹出层
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.clear(index);
                        });

                    }
                }
            })
        });

        //编辑里状态修改
        form.on('switch(ofilter)',function (data) {
            if (data.elem.checked){
                $('#flag').val(1);
            }if (!data.elem.checked){
                $('#flag').val(0);
            }
        })



    })
</script>
</body>
</html>
